"""
@author: zwz
@file: 13.回合制游戏.py
@time: 2022/12/2 0002 11:56:32
"""

# 角色    房间
# 角色 -- 属性
# 名字、性别、血量、装备、房间
# 战斗

# 房间 -- 属性
# 房间号，房间成员
# 加入房间

# 创建角色 创建房间 哪个房间开始战斗

class Role:
    def __init__(self, name, sex, hp, equip, room):
        self.name = name
        self.sex = sex
        self.hp = hp
        self.equip = equip
        self.room = room

    def harm(self, role):
        if self.equip == 1:
            self.hp -= 5
        if self.equip == 0:
            self.hp -= 10

class Room:
    def __init__(self, room_num, role1, role2):
        self.room_num = room_num
        self.role1 = role1
        self.role2 = role2

roles = {}
rooms = {}
role1 = Role("大蛇", "male", 100, 1, 0)
role2 = Role("施耐庵", "male", 100, 0, 0)
roles[role1.name] = role1
roles[role2.name] = role2

print("欢迎来到回合小游戏".center(40, "="))
while 1:
    print("1、选择角色\n2、创建角色")
    op = input("请输入你的选择：")
    if op == "q":
        break
    if op == "1":
        while 1:
            print("您拥有以下角色".center(30, "_"))
            for role in roles:
                print(role)
            role1 = input("请选择P1：")
            role2 = input("请选择P2：")
            print("对战房间".center(40, "_"))
            for room in rooms:
                print(room)
            room_num = input("请创建对战房间：")
            room = Room(room_num, role1, role2)
            if room_num in rooms:
                print("房间已存在！")
            else:
                rooms[room.room_num] = room
                print("开始战斗".center(20, "*"))
                i = 1
                while 1:
                    print(f"第{i}回合".center(10, "-"))
                    print(f"{role1}----->{role2}")
                    roles[role2].harm(role2)
                    print(f"{role2}----->{role1}")
                    roles[role1].harm(role1)
                    print(f"{role1}--HP:{roles[role1].hp}\n{role2}--HP:{roles[role2].hp}")
                    i += 1
                    if roles[role1].hp <= 0 and roles[role2].hp <= 0:
                        print("平局！")
                        break
                    elif roles[role1].hp >0 and roles[role2].hp <= 0:
                        print(f"{role1}胜利！")
                        break
                    elif roles[role2].hp > 0 and roles[role1].hp <= 0:
                        print(f"{role2}胜利！")
                        break

    if op == "2":
        print("创建角色".center(30, "_"))
        name = input("请输入角色名：")
        sex = input("请输入性别（male或fmale）:")
        equip = int(input("请选择有无装备（0或1）："))
        role = Role(name, sex, 100, equip, 0)
        roles[name] = role

    else:
        print("输入不合法！")
